package com.tsinghua.discharge.controller;

import com.github.pagehelper.PageInfo;
import com.tsinghua.discharge.common.ServerResponse;
import com.tsinghua.discharge.model.FileUploadRecord;
import com.tsinghua.discharge.service.FileUploadRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/fileRecord")
public class FileUploadRecordController {

    @Autowired
    FileUploadRecordService fileUploadRecordService;
    @RequestMapping(value = "/AddFileRecord.do",method = RequestMethod.GET)
    public ServerResponse addRecord(@RequestParam("file") MultipartFile file, @RequestBody FileUploadRecord fileuploadRecord, HttpSession session){
        return fileUploadRecordService.addRecord(file,fileuploadRecord,session);
    }
    @RequestMapping(value = "/fileRecordList.do",method = RequestMethod.GET)
    public ServerResponse<PageInfo> getList(@RequestParam(value = "page",defaultValue = "1") Integer page, @RequestParam(value = "limit",defaultValue = "10")Integer limit,
                                            @RequestParam(value = "fileType")String fileType, HttpSession session){
        return fileUploadRecordService.getList(page,limit,fileType,session);
    }
    @RequestMapping(value = "/fileSectorRecordList.do",method = RequestMethod.GET)
    public ServerResponse<PageInfo> getListBySector(@RequestParam(value = "page",defaultValue = "1") Integer page, @RequestParam(value = "limit",defaultValue = "10")Integer limit,
                                                    @RequestParam(value = "fileType") String fileType, HttpSession session,@RequestParam("sector") String sector){
        return fileUploadRecordService.getListBySector(page,limit,fileType,session,sector);
    }
}
